package com.tanhua.server.controller;

import com.tanhua.domain.vo.MomentVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.PublishVo;
import com.tanhua.domain.vo.VisitorVo;
import com.tanhua.server.service.MovementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 圈子模块-控制层
 */
@RestController
@RequestMapping("/movements")
public class MomentController {

    @Autowired
    private MovementsService movementsService;

    /**
     * 发布动态
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity movements(PublishVo publishVo,MultipartFile[] imageContent){
        movementsService.movements(publishVo,imageContent);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询好友动态
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity queryMovements(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize){
        PageResult<MomentVo> pageResult = movementsService.queryMovements(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }



    /**
     * 查询推荐动态
     */
    @RequestMapping(value = "/recommend",method = RequestMethod.GET)
    public ResponseEntity queryRecommend(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize){
        PageResult<MomentVo> pageResult = movementsService.queryRecommend(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 我的动态
     */
    @RequestMapping(value = "/all",method = RequestMethod.GET)
    public ResponseEntity queryMyAlbum(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize,Long userId){
        PageResult<MomentVo> pageResult = movementsService.queryMyAlbum(page,pagesize,userId);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 动态点赞
     */
    @RequestMapping(value = "/{id}/like",method = RequestMethod.GET)
    public ResponseEntity like(@PathVariable("id") String publishId){
        Long likeCount = movementsService.like(publishId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 动态取消点赞
     */
    @RequestMapping(value = "/{id}/dislike",method = RequestMethod.GET)
    public ResponseEntity dislike(@PathVariable("id") String publishId){
        Long likeCount = movementsService.dislike(publishId);
        return ResponseEntity.ok(likeCount);
    }



    /**
     * 动态喜欢
     */
    @RequestMapping(value = "/{id}/love",method = RequestMethod.GET)
    public ResponseEntity love(@PathVariable("id") String publishId){
        Long loveCount = movementsService.love(publishId);
        return ResponseEntity.ok(loveCount);
    }

    /**
     * 动态取消喜欢
     */
    @RequestMapping(value = "/{id}/unlove",method = RequestMethod.GET)
    public ResponseEntity unlove(@PathVariable("id") String publishId){
        Long unloveCount = movementsService.unlove(publishId);
        return ResponseEntity.ok(unloveCount);
    }


    /**
     * 查询单条动态
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public ResponseEntity queryById(@PathVariable("id") String publishId){
        MomentVo momentVo = movementsService.queryById(publishId);
        return ResponseEntity.ok(momentVo);
    }


    /**
     * 谁看过我
     */
    @RequestMapping(value = "/visitors",method = RequestMethod.GET)
    public ResponseEntity lookeMe(){
        List<VisitorVo> visitorVoList = movementsService.lookeMe();
        return ResponseEntity.ok(visitorVoList);
    }
}
